﻿#region Copyright

// All Material Copyright © 2008-2010 Dynamic Concepts Development Corp., All Rights Reserved
// 
// For further information please contact SoftwareSupport@dynconcepts.com
// 
// Dynamic Concepts Development Corp.  311 W 57th St. Suite #422, New York, NY 10019

#endregion

#region Using References

using System.Collections;
using System.Collections.Generic;

#endregion

namespace DynConDev.CorpLib.CommandLineParser
{
    public class ParameterCollection : IEnumerable<Parameter>
    {
        private readonly List<Parameter> r_ParametersByIndex = new List<Parameter>();
        private readonly Dictionary<string, Parameter> r_ParametersByName = new Dictionary<string, Parameter>();

        public int Count
        {
            get { return r_ParametersByIndex.Count; }
        }

        public Parameter this[int index]
        {
            get { return r_ParametersByIndex[index]; }
        }

        public Parameter this[string name]
        {
            get { return r_ParametersByName[name]; }
        }

        #region IEnumerable<Parameter> Members

        public IEnumerator<Parameter> GetEnumerator()
        {
            return r_ParametersByIndex.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return r_ParametersByIndex.GetEnumerator();
        }

        #endregion

        internal void Append(Parameter parameter)
        {
            r_ParametersByName.Add(parameter.ParameterName, parameter);
            r_ParametersByIndex.Add(parameter);
        }
    }
}